//
//  MSBankCardListController.m
//  觅尚
//
//  Created by No.8 on 2019/4/26.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSBankCardListController.h"
#import "MSBackCardModel.h"
#import "MSBankCardListCell.h"

#import "MSBuidingBankCardController.h"

@interface MSBankCardListController ()<UITableViewDelegate,UITableViewDataSource>
/** 数组*/
@property(nonatomic,strong)NSMutableArray *bankcardList;

/** 列表*/
@property(nonatomic,strong)UITableView *tableView;


@end

@implementation MSBankCardListController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self ReloadData];
        
    });
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self tableView];
    
    [self CreatFootView];
    
}
- (void)CreatFootView{
    UIView * FootView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 90 * px)];
    FootView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:FootView];
    
    
    self.addButton = [[MSAddBankCardButton alloc] initWithFrame:CGRectMake(ScreenWidth / 2 - 210 * px, 0, 420 * px, 90 * px)];
    [self.addButton setImage:[UIImage imageNamed:@"数量加"] forState:UIControlStateNormal];
    self.addButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [self.addButton setTitle:@"添加银行卡" forState:UIControlStateNormal];
//    [self.addButton addTarget:self action:@selector(AddButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.addButton setTitleColor:WYCRGBColor(95, 207, 105) forState:UIControlStateNormal];
    [FootView addSubview:self.addButton];
    
    self.tableView.tableFooterView = FootView;
    
    
}

//- (void)AddButtonClick{
//    MSBuidingBankCardController * buidingVC = [[MSBuidingBankCardController alloc] init];
//    [self.navigationController pushViewController:buidingVC animated:NO];
//    
//}
- (void)ReloadData{
    
    NSDictionary * params = @{@"uid":[WYCAccountTool unarchiveuid]};
    [HTTPRequest POST:MSgetBankcard params:params succeed:^(id responseObject) {
        
        if (CodeStr) {
            self.bankcardList = [MSBackCardModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"bankcardList"]];
        }else{
            
            [MBManager showBriefAlert:responseObject[@"msg"]];
            
        }
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [MBManager showBriefAlert:Failed];
    }];
}
/** 表视图*/
- (UITableView *)tableView{
    self.extendedLayoutIncludesOpaqueBars = YES;
    if (!_tableView) {
        
        if (@available(iOS 11.0, *)) {
            
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        } else {
            
            self.automaticallyAdjustsScrollViewInsets = NO;
            
        }
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:self.tableView];
    }
    return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.bankcardList.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 140 * px;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    MSBankCardListCell * cell = [MSBankCardListCell cellWithTableView:tableView];
    tableView.backgroundColor = backgroundcolor;
    //无色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.BackCardModel = self.bankcardList[indexPath.row];
    //    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MSBackCardModel *BackCardModel = self.bankcardList[indexPath.row];
    
    if (self.SettlementButtonDelegate && [self.SettlementButtonDelegate respondsToSelector:@selector(ClickselectIndexRowbanid:cardNumber:userName:bankName:)]) {
        [self.SettlementButtonDelegate ClickselectIndexRowbanid:BackCardModel.banid cardNumber:BackCardModel.cardNumber userName:BackCardModel.userName bankName:BackCardModel.bankName];
    }
}
@end
